package com.gws.ievent.common.utils;

import org.springframework.scheduling.support.CronExpression;

import java.time.LocalDateTime;

/**
 * @author song
 * @date 2022/10/18 22:08
 */
public class CronUtil {

    /**
     * 获取cron表达式下一次的执行时间
     *
     * @param cron
     * @return
     */
    public static LocalDateTime next(String cron) {
        LocalDateTime now = LocalDateTime.now();
        CronExpression cronExpression = CronExpression.parse(cron);
        return cronExpression.next(now);
    }


    /**
     * 获取cron表达式下一次的下一次执行时间
     *
     * @param cron
     * @param next
     * @return
     */
    public static LocalDateTime nextNext(String cron, LocalDateTime next) {
        return CronExpression.parse(cron).next(next);
    }


}
